package com.yulongtian.oneProblemEveryDay.month202301;

import java.util.Arrays;

/**
 * @author yulongTian
 * @create 2023-01-13 22:19
 */
public class Test11 {
    public static void main(String[] args) {
        System.out.println(rearrangeCharacters("ccccndxxlzerbsrrkvdnlvynxbjtjldsqgevphdlrldyishznryttvuratvwiafiwyjklafesvmcexuacxqgmnokfljxkystcbef", "bvciovnpto"));
    }

    public static int rearrangeCharacters(String s, String target) {
        int[] chs = new int[26];
        int[] cht = new int[26];
        int[] res = new int[26];
        int ans = Integer.MAX_VALUE;

        for (int i = 0; i < s.length(); i++) {
            chs[s.charAt(i) - 'a']++;
        }
        for (int i = 0; i < target.length(); i++) {
            cht[target.charAt(i) - 'a']++;
        }

//        System.out.println(Arrays.toString(chs));
//        System.out.println(Arrays.toString(cht));

        for (int i = 0; i < cht.length; i++) {
            if (cht[i] > chs[i]) {
                return 0;
            }
        }

        for (int i = 0; i < cht.length; i++) {
            if (cht[i] == 0) {
                continue;
            }
            res[i] = chs[i] / cht[i];
        }
        for (int re : res) {
            if (re != 0) {
                ans = Math.min(ans, re);
            }
        }

        return ans;
    }

}
